package demo2;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        //1.添加元素:无序,不重复,无索引。
        Map<String , Integer> maps = new HashMap<>();
        maps.put( "iphoneX",10);
        maps.put("娃娃",31);
        maps.put("iphoneX",100); //Hap集合后面重复的键对应的元素会覆盖前面重复的整个元素!
        maps.put( "huawei" , 1000);
        maps.put("生活用品",10);maps.put("手表",10);
        System.out.println(maps);
        //2.清空集合
//        maps.clear();
//        System.out.println(maps);
        //3.判断集合是否为空，为空返回true，反之为false
        System.out.println(maps.isEmpty());
        //4.根据键获取对应值: public v get(object key)
        Integer value = maps.get("huawei");
        System.out.println(value);
        //5.根据键删除整个元素。〔删除键会返回键的值)
        System.out.println(maps.remove("iphoneX"));
        //6.判断是否包含某个键，包含返回true ,反之
        System.out.println(maps.containsKey("娃娃"));//true
        System.out.println(maps.containsKey("娃娃2"));//false
        System.out.println(maps.containsKey( "iphonex"));//false
        //7.判断是否包含某个值。
        System.out.println(maps.containsValue(100));
        System.out.println(maps.containsValue(1));
        System.out.println(maps.containsValue(22));
        //8.获取全部健的集合:public Set<K> keySet()
        Set<String> sets = maps.keySet();
        System.out.println(sets);
        //9.获取全部值的集合:public Collection<V> values();
        Collection<Integer> integers = maps.values();
        System.out.println(integers);
        //10.集合大小
        System.out.println(maps.size());
        System.out.println("-------------------------------------");
        //11.合并其他集合
        Map<String , Integer> map1 = new HashMap<>();
        map1.put( "java1",1);
        map1.put( "java2",100);
        Map<String , Integer> map2 = new HashMap<>();
        map2.put( "java2" ,1);
        map2.put( "java3",100);
        map1.putAll(map2);//把集合map2的元素拷贝一份到map1中去
        System.out.println(map1);

    }
}
